package www.shw.com.rabbitmq;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import www.shw.com.bean.LvEx;
import www.shw.com.mapper.LvMapper;

//@Component
public class ConsumerListen {

	@Resource
	private  LvMapper lvMapper;
	//创建json的处理对象
	private ObjectMapper objectMapper = new ObjectMapper();
	
	@RabbitListener(queues= {"myqueue"})
	public void listen(String json) {
		System.out.println("接收的消息是:"+json);
		try {
			//转化成实体Bean对象
			LvEx lv = objectMapper.readValue(json,LvEx.class);
			//插入中间表
			lvMapper.insertMiddle(lv);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
